<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>采购单管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<jsp:include page="../../layout/script.jsp"></jsp:include>
	<script type="text/javascript">
		var $dg;
		var $grid;
		$(function(){
			$dg = $("#dg");
			$grid=$dg.datagrid({
				url : "orderPurchase/orderPurchaseAction!findPurchaseOrderList.action",
				width : 'auto',
				height : $(this).height()-85,
				pagination:true,
				rownumbers:true,
				border:true,
				striped:true,
				singleSelect:true,
				columns : [ [ {field : 'myid',title : '采购单号',width : parseInt($(this).width()*0.2)},
				        {field : 'className',title : '采购类型',width : parseInt($(this).width()*0.05),
						formatter:function(value,row){
				      			return "<font color=red>"+row.className+"</font>";  
						}},
				        {field : 'suplierName',title : '供应商名称',width : parseInt($(this).width()*0.15),align : 'left'},
				        {field : 'suplierMyid',title : '供应商编码',width : parseInt($(this).width()*0.1),align : 'left'},
				        {field : 'suplierContact',title : '联系人',width : parseInt($(this).width()*0.1),align : 'left'},
				        {field : 'suplierTel',title : '电话',width :parseInt($(this).width()*0.1),align : 'left'},
				        {field : 'buyerOrganizationName',title : '采购部门',width : parseInt($(this).width()*0.05),align : 'left'},
				        {field : 'description',title : '备注',width : parseInt($(this).width()*0.2),align : 'left'}
				] ],
				toolbar:'#tb'
			});
			
			$("#searchbox").searchbox({
				menu:"#mm", 
				prompt :'模糊查询',
				searcher:function(value,name){   
					var str="{\"searchName\":\""+name+"\",\"searchValue\":\""+value+"\"}";
			        var obj = eval('('+str+')');
			        $dg.datagrid('reload',obj); 
				}
			});
		});
		
		function delRows(){
			var row = $dg.datagrid('getSelected');
			if(row){
				parent.$.messager.confirm("提示","确定要删除记录吗?",function(r){
					var rowIndex = $dg.datagrid('getRowIndex', row);
					$dg.datagrid('deleteRow', rowIndex);
					$.ajax({
						url:"orderPurchase/orderPurchaseAction!delOrderPurchase.action",
						data: "orderPurchaseId="+row.orderPurchaseId,
						success: function(rsp){
							parent.$.messager.show({
								title : rsp.title,
								msg : rsp.message,
								timeout : 1000 * 2
							});
						}
					});
				});
			}else{
				parent.$.messager.show({
					title : "提示",
					msg :"请选择一行记录!",
					timeout : 1000 * 2
				});
			}
		}
		
		function updRowsOpenDlg(){
			var row = $dg.datagrid('getSelected');
			if(row){
				parent.$.modalDialog({
					title : '编辑采购单',
					width : 1200,
					height :700,
					href : "jsp/orderPurchase/orderPurchaseEditDlg.jsp?tempId="+row.orderPurchaseId,
					onLoad:function(){
						var f = parent.$.modalDialog.handler.find("#form");
						f.form("load", row);
					},
					buttons:[{
						text:'保存',
						iconCls:'icon-ok',
						handler:function(){
							parent.$.modalDialog.openner= $grid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
							var f = parent.$.modalDialog.handler.find("#form");
							f.submit();
						}
					},{
						text:'取消',
						iconCls:'icon-cancel',
						handler : function() {
							$(document).unbind("keydown");
							parent.$.modalDialog.handler.dialog('destroy');
							parent.$.modalDialog.handler = undefined;
						}
					}],
					onClose:function(){
						parent.$.modalDialog.handler.dialog('destroy');
						parent.$.modalDialog.handler = undefined;
						$(document).unbind("keydown");
					}
				});
			}else{
				parent.$.messager.show({
					title :"提示",
					msg :"请选择一行记录!",
					timeout : 1000 * 2
				});
			}
		}
		
		function addRowsOpenDlg(){
			parent.$.modalDialog({
				title : '添加采购单',
				width : 1200,
				height :700,
				href : "jsp/orderPurchase/orderPurchaseEditDlg.jsp",
				buttons:[{
					text:'保存',
					iconCls:'icon-ok',
					handler:function(){
						parent.$.modalDialog.openner=$grid;
						var f=parent.$.modalDialog.handler.find("#form");
						f.submit();
					}
				},{
					text:'取消',
					iconCls:'icon-cancel',
					handler:function(){
						parent.$.modalDialog.handler.dialog('destroy');
						parent.$.modalDialog.handler = undefined;
						$(document).unbind("keydown");
					}
				}],
				onClose:function(){
					parent.$.modalDialog.handler.dialog('destroy');
					parent.$.modalDialog.handler = undefined;
					$(document).unbind("keydown");
				}
			});
		}
	</script>
  </head>
  <body>
      <div data-options="region:'center',border : false">
  		<div class="well well-small" style="margin-left: 5px;margin-top: 5px">
				<span class="badge">提示</span>
				<p>
					在此你可以对<span class="label-info"><strong>采购单</strong></span>进行，新增，编辑，删除!
				</p>
		</div>
		<div id="tb" style="padding:2px 0">
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td style="padding-left:2px">
						<shiro:hasPermission name="projectAdd">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addRowsOpenDlg();">添加</a>
						</shiro:hasPermission>
						<shiro:hasPermission name="projectEdit">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="updRowsOpenDlg();">编辑</a>
						</shiro:hasPermission>
						<shiro:hasPermission name="projectDel">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delRows();">删除</a>
						</shiro:hasPermission>
					</td>
					<td style="padding-left:2px">
						<input id="searchbox" type="text"/>
					</td>
				</tr>
			</table>
		</div>
		<div id="mm">
				<div name="myid">采购单编码</div>
		</div>
		<table id="dg" title="采购单管理"></table>
  	</div>	
  </body>
</html>
